/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 script_sequence.h

	$Header: /heroes4/script_sequence.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( SCRIPT_SEQUENCE_H_INCLUDED )
#define SCRIPT_SEQUENCE_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <cassert>
#include <iosfwd>
#include <vector>

#include "abstract_script_action.h"
#include "counted_ptr.h"

// --------------------------------------------------------------------------
// t_script_sequence class
// --------------------------------------------------------------------------

class t_script_sequence : public t_abstract_script_action
{
public:
	// Types
	typedef t_abstract_script_action	t_subaction;

	// Constructors
	t_script_sequence() {}
	t_script_sequence( t_script_sequence const & other );

	// Member functions
	t_subaction const &	get_subaction( int num ) const;
	int					get_subaction_count() const;

	virtual void		execute(t_script_context_hero const& context) const;
	virtual void		execute(t_script_context_town const& context) const;
	virtual void		execute(t_script_context_object const& context) const;
	virtual void		execute(t_script_context_army const& context) const;
	virtual void		execute(t_script_context_global const& context) const;

	virtual void		executed_subaction(const t_subaction& subaction) const {}

	virtual bool		read( std::streambuf& stream, int version );
	virtual bool		read_from_map(
							std::streambuf &	stream,
							int					format_version );
	virtual bool		write( std::streambuf& stream ) const;

private:
	// Types
	typedef t_counted_ptr< t_subaction >		t_subaction_ptr;
	typedef std::vector< t_subaction_ptr >		t_subaction_ptr_list;

	// Data members
	t_subaction_ptr_list	m_subaction_ptrs;
};

// --------------------------------------------------------------------------
// t_script_sequence inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_script_sequence::t_subaction const &
t_script_sequence::get_subaction( int num ) const
{
	assert( num >= 0 && num < get_subaction_count() );
	return *m_subaction_ptrs[ num ];
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline int t_script_sequence::get_subaction_count() const
{
	return m_subaction_ptrs.size();
}

SPECIALIZE_SCRIPT_ACTION( k_script_action_sequence, t_script_sequence );

#endif // !defined( SCRIPT_SEQUENCE_H_INCLUDED )
